/**
 * Created by huotaol on 2017/5/11.
 */
import React, {Component} from "react";
import PropTypes from "prop-types";
import {View} from "react-native";
import ViewPager from "react-native-viewpager";
import {Actions} from "react-native-router-flux";
import BottomHandle from "./BottomHandle";
import ModuleCommonHeader from "../../main/module/ModuleCommonHeader";
import Gallery from "react-native-gallery";

const DATA_SOURCE = new ViewPager.DataSource({
    pageHasChanged: (p1, p2) => p1 !== p2,
});

export default class CarGallery extends Component {

    static propTypes = {
        carInfo: PropTypes.object,
        picList: PropTypes.array,
    };

    // 构造
    constructor(props) {
        super(props);
        // 初始状态
        this.state = {picList: []};
    }

    componentDidMount() {
        this.setState({picList: this.props.picList});
    }

    render() {
        const {carInfo, picList} = this.props;
        return (
            <View style={{flex: 1}}>
                <ModuleCommonHeader rightText={'全部图片'} clickedRight={() => {
                    Actions.CarGalleryAll({
                        carInfo, picList, select: (index) => {
                        }
                    });
                }}/>
                <Gallery
                    style={{flex: 1, backgroundColor: 'black'}}
                    images={this.state.picList}
                />
                {this._renderBottom(carInfo)}
            </View>
        );
    }

    _renderBottom(carInfo) {
        if (carInfo) {
            return <BottomHandle carInfo={carInfo}/>
        }
    }
}